DAY2:String ends with?


Posted by birdbirdmurmur on 2023-07-15

題目連結:

解題過程:

  • 第一個想法是直接用includes(),以為可以輕鬆通過
    • 原以為includes()無法判斷string
      • 有想過要不要先判斷型態
    • 被自己笨死,看錯題目(請好好練英文x
  • 搞懂題目之後,翻開MDN字典
    • 使用endsWith()可快速判斷字串的結尾
      • 可以區分大小寫
  • Done.

解法:

function solution(str, ending){
  return str.endsWith(ending);
}

參考資料:


#javascript #Codewars #endWith







Related Posts

CSS 衍生的資安問題(下) - 我愛偷甚麼就偷甚麼

CSS 衍生的資安問題(下) - 我愛偷甚麼就偷甚麼

[進階 js 05] hoisting(提升)

[進階 js 05] hoisting(提升)

瀏覽器渲染流程

瀏覽器渲染流程


Comments